package com.mycompany.app.hr.security.model;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

import com.mycompany.app.common.audit.modification.model.AuditEmbeddedObject;

@SuppressWarnings("unchecked")
@Entity
@Table(name = "s_role")
public class SystemRole {
    @Id
    @Column(name = "role_id")
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @Column(name = "role_type_code")
    private String roleTypeCode;

    @Column(name = "role_name")
    private String roleName;

    private String description;

    @Column(name = "is_active")
    private Boolean isActive;

    @Embedded
    private AuditEmbeddedObject auditEmbeddedObject=new AuditEmbeddedObject();
    
    @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    @JoinTable(name = "s_user_role", joinColumns = { @JoinColumn(name = "role_id") }, inverseJoinColumns = { @JoinColumn(name = "user_id") })
    private Set<SystemUser> users = new HashSet<SystemUser>(0);
    
    @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @JoinTable(name = "s_role_permission", joinColumns = { @JoinColumn(name = "role_id") }, inverseJoinColumns = { @JoinColumn(name = "permission_id") })
    private Set<SystemPermission> permissions=new HashSet<SystemPermission>(0);

    // ===================================
    @Override
    public String toString() {

        return ToStringBuilder.reflectionToString(this,
                ToStringStyle.SHORT_PREFIX_STYLE);
    }

    // ===================================

    public Long getId() {

        return id;
    }

    public void setId(Long id) {

        this.id = id;
    }

    public String getRoleTypeCode() {

        return roleTypeCode;
    }

    public void setRoleTypeCode(String roleTypeCode) {

        this.roleTypeCode = roleTypeCode;
    }

    public String getRoleName() {

        return roleName;
    }

    public void setRoleName(String roleName) {

        this.roleName = roleName;
    }

    public String getDescription() {

        return description;
    }

    public void setDescription(String description) {

        this.description = description;
    }

    public AuditEmbeddedObject getAuditEmbeddedObject() {

        return auditEmbeddedObject;
    }

    public void setAuditEmbeddedObject(AuditEmbeddedObject auditEmbeddedObject) {

        this.auditEmbeddedObject = auditEmbeddedObject;
    }

    public Boolean getIsActive() {

        return isActive;
    }

    public void setIsActive(Boolean isActive) {

        this.isActive = isActive;
    }

    public Set<SystemUser> getUsers() {
    
        return users;
    }

    public void setUsers(Set<SystemUser> users) {
    
        this.users = users;
    }

    public Set<SystemPermission> getPermissions() {
    
        return permissions;
    }

    public void setPermissions(Set<SystemPermission> permissions) {
    
        this.permissions = permissions;
    }

}
